export function createHandle(name) {
  return function(e) {
    const { props } = this.data
    if (typeof props[name] === 'function') {
      props[name](e)
    }
  }
}

export function isShallowEqual(objA,objB){
  if(objA === objB) {
    return true
  }

  if(!(typeof objA === 'object' && objA !== null) || !(typeof objB === 'object' && objB !== null)) {
    return false
  }

  const keysA = Object.keys(objA)
  const keysB = Object.keys(objB)

  if (keysA.length !== keysB.length) {
    return false
  }

  for (let i = 0; i < keysA.length; i ++) {
    const keyA = keysA[i]
    const keyB = keysB[i]

    if (!Object.prototype.hasOwnProperty.call(objB, keyA)) {
      return false
    }

    if (!Object.prototype.hasOwnProperty.call(objA, keyB)) {
      return false
    }

    if (objA[keyA] !== objB[keyA]) {
      return false
    }

    if (objA[keyB] !== objB[keyB]) {
      return false
    }
  }

  return true
}

export function createRandomString(len = 16) {
  const CHARS = '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ'
  let text = ''
  for (let i = 0; i < len; i++) {
    text += CHARS.charAt(Math.floor(Math.random() * CHARS.length))
  }
  return text
}
